package com.canoe.text;

import com.canoe.AbstractFirstLevelOrderProcessor;
import com.canoe.common.CanoeException;
import com.canoe.common.FirstLevelOrder;
import com.canoe.text.common.TextOrder;

import java.util.Objects;

/**
 * text命令处理器
 *
 * @author: btm
 * @time: 21:46 2020/9/21
 **/
public final class TextProcessor extends AbstractFirstLevelOrderProcessor {

    private static final TextOrderAdapter TEXT_ORDER_ADAPTER = new TextOrderAdapter();

    @Override
    public FirstLevelOrder support() {
        return FirstLevelOrder.TEXT;
    }

    @Override
    public void doProcess(String... args) {
        TextOrder textOrder = TextOrder.findByOrderName(args[0]);
        if (Objects.isNull(textOrder)) {
            throw new CanoeException("the order type ["+args[0]+"] is not supported");
        }
        TEXT_ORDER_ADAPTER.getProcessor(textOrder).process(args);
    }
}
